package org.qengine.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.qengine.entity.DicTypeEntity;
import org.qengine.service.DicTypeService;
import org.qengine.service.DicTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("dicType/")
public class DicTypeController {

    @Autowired
    private DicTypeService dicTypeService;

    @PostMapping("/add")
    public String add(@RequestBody DicTypeEntity dicTypeEntity){
        Integer i =dicTypeService.add(dicTypeEntity);
        if(i>0){
            return "success";
        }
        else{
            return "fail";
        }
    }

    @PostMapping("/delete/{id}")
    public String deleteById(@PathVariable Long id){
        Integer i = dicTypeService.delete(id);
        if(i>0){
            return "success";
        }
        else{
            return "fail";
        }
    }

    @PostMapping("/update")
    public String update(@RequestBody DicTypeEntity dicTypeEntity){
        Integer i = dicTypeService.update(dicTypeEntity);
        if(i>0){
            return "success";
        }
        else{
            return "fail";
        }
    }

    @PostMapping("/getById/{id}")//根据id查找
    public DicTypeEntity getById(@PathVariable Long id){
        return dicTypeService.getById(id);
    }

    @PostMapping("/getByName")
    //通过typeName查到id,然后可在/dataDict/search路径通过该id查对应的多个dicName
    public Long getByName(@RequestBody DicTypeEntity dicTypeEntity){
        return dicTypeService.queryByTypeName(dicTypeEntity).getId();
    }
}
